<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>释放结果内存</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-field-type.html">mysql_field_type</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-get-client-info.html">mysql_get_client_info</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mysql-free-result" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_free_result</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_free_result</span> &mdash; <span class="dc-title">释放结果内存</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.mysql-free-result-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">bool</span> <span class="methodname"><strong>mysql_free_result</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
      )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>mysql_free_result()</strong></span> 将释放所有与结果标识符
     <em><code class="parameter">result</code></em> 所关联的内存。
    </p>
    <p class="para">
     <span class="function"><strong>mysql_free_result()</strong></span>
     仅需要在考虑到返回很大的结果集时会占用多少内存时调用。在脚本结束后所有关联的内存都会被自动释放。
     
    </p>
    <p class="para">
     成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
    </p>
    <p class="para">
     为向下兼容仍然可以使用
     <span class="function"><strong>mysql_freeresult()</strong></span>，但反对这样做。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-free-result-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<em><code class="parameter">
result</code></em></dt>
<dd>
<p class="para"><span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>
型的结果集。此结果集来自对 <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span>
的调用。</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-free-result-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
  <p class="para">
   If a non-resource is used for the <em><code class="parameter">result</code></em>, an
   error of level E_WARNING will be emitted.  It&#039;s worth noting that
   <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> only returns a <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>
   for SELECT, SHOW, EXPLAIN, and DESCRIBE queries.
  </p>
 </div>

 
  <div class="refsect1 examples" id="refsect1-function.mysql-free-result-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1567">
    <p><strong>Example #1 A <span class="function"><strong>mysql_free_result()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,email&nbsp;FROM&nbsp;people&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;'42'"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;run&nbsp;query:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /></span><span style="color: #FF8000">/*&nbsp;Use&nbsp;the&nbsp;result,&nbsp;assuming&nbsp;we're&nbsp;done&nbsp;with&nbsp;it&nbsp;afterwards&nbsp;*/<br /></span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Now&nbsp;we&nbsp;free&nbsp;up&nbsp;the&nbsp;result&nbsp;and&nbsp;continue&nbsp;on&nbsp;with&nbsp;our&nbsp;script&nbsp;*/<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'id'</span><span style="color: #007700">];<br />echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'email'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-free-result-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    为了向下兼容，可以使用下列已废弃的别名：
    <span class="function"><strong>mysql_freeresult()</strong></span>
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-free-result-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mysql-query.html" class="function" rel="rdfs-seeAlso">mysql_query()</a> - 发送一条 MySQL 查询</span></li>
    <li class="member"><span class="function"><a href="function.is-resource.html" class="function" rel="rdfs-seeAlso">is_resource()</a> - 检测变量是否为资源类型</span></li>
   </ul>
  </p>
 </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-field-type.html">mysql_field_type</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-get-client-info.html">mysql_get_client_info</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
